package com.andy.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestUtils1 {

	public static final Integer SINGLE_TEST_TYPE = 1;
	
	public static final Integer MULTI_TEST_TYPE = 2;

	public static final Integer MULTI_TEST_COUNT = 10;
	
	/**
	 * 计算各种题目类型的数量<br />
	 * 目前设：多选题必有10题，单选题任意
	 * 
	 * @param totalCount
	 * @param totalScore
	 * @param testTypeScore
	 * @return
	 */
	public static Map<Integer, Integer> caculateTestTypeCount(Integer totalCount, BigDecimal totalScore, Map<Integer, Integer> testTypeScore) {
		Integer totalMultiScore = (MULTI_TEST_COUNT * testTypeScore.get(MULTI_TEST_TYPE));
		if (totalCount.compareTo(MULTI_TEST_COUNT) >= 0 && totalScore.compareTo(new BigDecimal(totalMultiScore)) >= 0) {
			Map<Integer, Integer> resultMap = new HashMap<Integer, Integer>();
			resultMap.put(MULTI_TEST_TYPE, MULTI_TEST_COUNT);
			if ((totalScore.subtract(new BigDecimal(totalMultiScore)))	// 总分数 - 多选总分
					.remainder(new BigDecimal(testTypeScore.get(SINGLE_TEST_TYPE)))	// (总分数 - 多选总分) % 单选每题分
						.compareTo(BigDecimal.ZERO) == 0) {	// (总分数 - 多选总分) % 单选每题分 == 0
				resultMap.put(SINGLE_TEST_TYPE, totalCount - MULTI_TEST_COUNT);
				return resultMap;
			} else {
				return null;
			}
		}
		return null;
	}
	
	/**
	 * 获取相应数量的随机题号
	 * 
	 * @param originList
	 * @param randomCount
	 * @return
	 */
	public static List<Integer> getRandomList(List<Integer> originList, Integer randomCount) {
		if (originList != null && randomCount != null) {
			if (randomCount.compareTo(originList.size()) == 0) {
				return originList;
			} else if (randomCount.compareTo(originList.size()) < 0) {
				List<Integer> resultRandomList = new ArrayList<Integer>();
				int currentOriginListSize = originList.size();
				for (int i = 0; i < randomCount; i ++) {
					int randomNumber = ((int)(Math.random() * currentOriginListSize));
					resultRandomList.add(originList.get(randomNumber));
					originList.remove(randomNumber);
					currentOriginListSize = originList.size();
				}
				return resultRandomList;
			} else {
				return null;
			}
		}
		return null;
	}
	
}
